﻿using hyjx;
using hyjx.bind;
using GanFengLogViewer.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GanFengLogViewer.Models
{
    /// <summary>
    /// 筛选模型
    /// </summary>
    public class FilterModel : BindableBase
    {
        /// <summary>
        /// 创建一个新的筛选模型
        /// </summary>
        public FilterModel() 
        {
            InterfaceIds.Add(200, "200：MES 心跳");
            InterfaceIds.Add(201, "201：配方下发");
            InterfaceIds.Add(202, "202：工步运行");
            InterfaceIds.Add(203, "203：物料匹配");
            InterfaceIds.Add(204, "204：读取配方");
            InterfaceIds.Add(205, "205：工步状态变更");
            InterfaceIds.Add(206, "206：报警");
            InterfaceIds.Add(207, "207：实时状态");
            InterfaceIds.Add(210, "210：储罐上料");
            InterfaceIds.Add(211, "211：储罐上料完成");
            InterfaceIds.Add(212, "212：成品或中转罐状态");
            InterfaceIds.Add(222, "222：稀释搅拌设置工步运行");
            InterfaceIds.Add(223, "223：稀释搅拌工步完成");
            InterfaceIds.Add(224, "224：稀释搅拌下发重量确认");
            InterfaceIds.Add(225, "225：稀释搅拌工步状态变更");
            InterfaceIds.Add(227, "227：稀释搅拌实时状态");
            InterfaceIds.Add(-1, "-1：异常");
            SelectedInterface = InterfaceIds.First();

            SortFields.Add("CreatedDatetime", "调用时间");
            SortFields.Add("DeviceCode", "设备编码");
            SortFields.Add("InterfaceId", "接口 ID");
            SelectedSortField = SortFields.First();

            OrderByFields.Add(OrderbyDirectionTypes.Ascending, "顺序");
            OrderByFields.Add(OrderbyDirectionTypes.Descending, "倒序");
            SelectedOrderByField = OrderByFields.First();
        }

        private string? _deviceCode;
        /// <summary>
        /// 设备编码
        /// </summary>
        public string? DeviceCode { get { return _deviceCode; } set { SetProperty(ref _deviceCode, value); } }
        /// <summary>
        /// 接口 ID 集
        /// </summary>
        public Dictionary<int, string> InterfaceIds { get; } = new Dictionary<int, string>();

        private KeyValuePair<int, string> _selectedInterface;
        /// <summary>
        /// 选中的接口 ID
        /// </summary>
        public KeyValuePair<int, string> SelectedInterface { get {  return _selectedInterface; } set { SetProperty(ref _selectedInterface,value); } }

        private DateTime? _startDate;
        /// <summary>
        /// 开始日期
        /// </summary>
        public DateTime? StartDate { get { return _startDate; } set { SetProperty(ref _startDate, value);} }

        private DateTime? _endDate;
        /// <summary>
        /// 截止日期
        /// </summary>
        public DateTime? EndDate { get { return _endDate;} set { SetProperty(ref _endDate, value); } }
        /// <summary>
        /// 排序字段集
        /// </summary>
        public Dictionary<string, string> SortFields { get; } = new Dictionary<string,string>();

        private KeyValuePair<string, string> _selectedSortField;
        /// <summary>
        /// 选中的排序字段
        /// </summary>
        public KeyValuePair<string,string> SelectedSortField { get { return _selectedSortField; } set { SetProperty(ref _selectedSortField, value); } }
        /// <summary>
        /// 排序顺序集
        /// </summary>
        public Dictionary<OrderbyDirectionTypes, string> OrderByFields { get; } = new Dictionary<OrderbyDirectionTypes, string>();

        private KeyValuePair<OrderbyDirectionTypes, string> _selectedOrderByField;
        /// <summary>
        /// 选中的排序顺序
        /// </summary>
        public KeyValuePair<OrderbyDirectionTypes, string> SelectedOrderByField { get { return _selectedOrderByField; } set { SetProperty(ref _selectedOrderByField, value); } }
        /// <summary>
        /// 筛选命令
        /// </summary>
        public FilterCommand FilterCommand { get; } = new();
    }
}
